<?php
/*
Engineer:  Alex Arey
Updated: 12/9/2011
Description: Handles submitting student application including the addition of references.
*/
 ?>

<?php if($this->existingapplication):?>
	<h3>You have already submitted an internship application for the current term.</h3>
	<h3>Use the options on the left to view your submitted applications.</h3>
<?php endif; ?>
<?php if(!($this->existingapplication)):?>
<?php if(!$this->open):?>
	<h3>There are no open terms for internship .</h3>
<?php endif;?>
<?php if($this->open):?>
<?php if(!$this->refform): ?>
<?php if($this->studentInfo): ?>
	<?php $si = $this->studentInfo; ?>
<h3>Your profile information to be submitted with this application</h3>
<p>If this is incorrect, please <a target="_blank" href = "
<?php echo $this->url(array('controller'=>'profile','action'=>'edit','type'=>'student')); ?>
">update your profile</a></p>
<dl>
	<dt style = "display:inline;">PID:</dt>
		<dd style = "display:inline;"><?php echo $si['PID'] ?></dd><br/>
	<dt style = "display:inline;">Name:</dt>
		<dd style = "display:inline;"><?php echo $si['FIRSTNAME'] . " " . $si['MIDDLENAME'] . " " . $si['LASTNAME'] ?></dd><br/>
	<dt style = "display:inline;">Email:</dt>
		<dd style = "display:inline;"><?php echo $si['EMAIL'] ?></dd><br/>
	<dt style = "display:inline;">Phone:</dt>
		<dd style = "display:inline;"><?php echo $si['PHONE'] ?></dd><br/>
	<dt style = "display:inline;">Major:</dt>
		<dd style = "display:inline;"><?php echo $si['MAJOR'] ?></dd><br/>
	<dt style = "display:inline;">Student Status:</dt>
		<dd style = "display:inline;"><?php echo $si['STUDENTSTATE'] ?></dd>
<?php endif; ?>
<?php endif; ?>
<h3>References for this application: (three references required)</h3>
<table>
	<tr>
		<th>Name</th>
		<th>Phone</th>
		<th>Address</th>
		<th>Relationship</th>
	</tr>
	<?php if($this->references): ?>
		<?php foreach($this->references as $r):?>
		<tr align="center">
			<td>
				<?php echo $r['NAME']; ?>
			</td>
			<td>
				<?php echo $r['PHONE']; ?>
			</td>
			<td>
				<?php echo $r['ADDRESS1']; ?><br/>
				<?php if($r['ADDRESS2'] && $r['ADDRESS1']!= "") echo $r['ADDRESS2'].'<br/>'; ?>
				<?php echo $r['CITY']. ",&nbsp;" . $r['STATE'] . "&nbsp;" . $r['ZIP']; ?>
			</td>
			<td>
				<?php echo $r['RELATIONSHIP']; ?>
			</td>
		<!--	<td>
				<a href = "<?php echo $this->url(array('reference'=>'remove', 'name'=>$r['NAME'],'phone'=>$r['PHONE'])) ?>">Delete</a>
			</td>-->
		</tr>
		<?php endforeach; ?>
		<?php if(count($this->references)!=3):?>
		<tr>
			<td colspan="5" align = "center"> 
				<a href = "<?php echo $this->url(array('reference'=>'add')) ?>">Add Reference.</a><br/>
					All references must be entered before continuing with the application.
			</td>
		</tr>
		<?php endif;?>
	<?php endif; ?>
	<?php if(!$this->references): ?>
		<tr>
			<td colspan="4" align = "center"> 
				No references added.&nbsp;<a href = "<?php echo $this->url(array('reference'=>'add')) ?>">Add Reference</a><br/>
					All references must be entered before continuing with the application.
			</td>
		</tr>
	<?php endif; ?>
</table>
	<?php if(count($this->references)==3):?>
		<h3>Application:</h3>
		<?php
			$this->form->setAction($this->url());
			echo $this->form;
		?>
		<?php //print error conditions
			if($this->willingposerror){
			echo "<p><strong>Position preferences must be unique.</strong></p>";
			}
		?>
	<?php endif;?>
<?php
	if($this->numcontactserror){
		echo "<p><strong>Three references required.</strong></p>";
	}
?>
<?php
	if($this->refform){
		$this->refform->setAction($this->url());
		echo $this->refform;
	}
?>
<?php endif;?>
<?php endif; ?>
